package org.huangrui.spark.java.sql;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import java.util.Properties;

/**
 * @Author hr
 * @Create 2024-10-20 20:10
 */
public class SparkSQL07_Source_MySQL {
    public static void main(String[] args) {
        SparkSession spark = SparkSession.builder().appName("SparkSQL07_Source_MySQL").master("local[2]").getOrCreate();


        Properties properties = new Properties();
        properties.setProperty("user","root");
        properties.setProperty("password","000000");
        Dataset<Row> jdbc = spark.read()
                .jdbc("jdbc:mysql://hadoop121:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true", "ws2", properties);

        jdbc.write()
                .jdbc("jdbc:mysql://hadoop121:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true", "ws2test", properties);

        jdbc.show();
        spark.stop();
    }
}
